package com.allwees.bs.c.module.order.context.listener;

import com.allwees.bs.c.module.ops.service.CashActiveDefUseService;
import com.allwees.bs.c.module.order.dto.OrderDTO;
import com.allwees.bs.c.module.order.mq.event.OrderReceivedMqEvent;
import com.allwees.bs.core.model.coupon.constant.ECashUseType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
public class OrderReceivedListener {

    @Autowired
    private CashActiveDefUseService cashActiveDefUseService;

    @Async
    @TransactionalEventListener
    public void onEvent(OrderReceivedMqEvent event) {

        OrderDTO order = (OrderDTO) event.getSource();

        log.info("received order event[orderUuid:{}]", order.getUuid());

        cashActiveDefUseService.inviterReceived(order.getUserUuid(), ECashUseType.SYSTEM_INVITEOR_RECEIVED);
    }
}
